package com.xh.petdogexpert.expert.controller;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xh.petdogexpert.base.BaseController;
import com.xh.petdogexpert.base.BaseException;
import com.xh.petdogexpert.base.ResponseData;
import com.xh.petdogexpert.expert.dto.DiseaseSymptomLink;
import com.xh.petdogexpert.expert.dto.Symptom;
import com.xh.petdogexpert.expert.service.ISymptomService;

@RequestMapping(value = "/expert")
@Controller
public class SymptomController extends BaseController {

	@Autowired
	ISymptomService symptomService;

	@Autowired
	HttpSession session;
	final static Logger logger = LoggerFactory.getLogger(SymptomController.class);

	@RequestMapping(value = "/querySymptom")
	@ResponseBody
	public ResponseData querySymptoms(Symptom symptom, @RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="10") Integer pageSize) {

		ResponseData rData = new ResponseData();
		List<Symptom> symptoms = symptomService.querySymptoms(symptom, page, pageSize);
		rData.setData(symptoms);
		return rData;
	}

	@RequestMapping(value = "/getSymptom")
	@ResponseBody
	public ResponseData getSymptom(Symptom symptom) throws BaseException {

		ResponseData rData = new ResponseData();
		Symptom rSymptom = null;

		rSymptom = symptomService.getSymptom(symptom);
		rData.setData(rSymptom);

		return rData;
	}

	@RequestMapping(value = "/addUpdateSymptom")
	@ResponseBody
	public ResponseData addUpdateSymptom(Symptom symptom) throws BaseException {

		ResponseData rData = new ResponseData();

		int id = symptomService.addUpdateSymptom(symptom);
		if (symptom.getId() != null) {
			rData.setMsg("修改症状成功");
		} else {
			rData.setMsg("新增症状成功");
		}
		rData.data = id;

		return rData;
	}

	@RequestMapping(value = "/deleteSymptom")
	@ResponseBody
	public ResponseData deleteSymptom(Symptom symptom) throws BaseException {

		ResponseData rData = new ResponseData();

		int count = symptomService.deleteSymptom(symptom);
		rData.setData(count);

		return rData;
	}

	@RequestMapping(value = "symptom/getSymptomsByKeyName")
	@ResponseBody
	public ResponseData getSymptomsByKeyName(String keyName) {

		return new ResponseData(symptomService.getSymptomsByKeyName(keyName));
	}

	// @RequestMapping(value="symptom/getLastSymptoms")
	// @ResponseBody
	// public List<Symptom> getLastSymptoms(@RequestParam(defaultValue =
	// "1")Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
	// return symptomService.getLastSymptoms(page, pageSize);
	// }
	@RequestMapping(value = "symptom/getSymptomsLink")
	@ResponseBody
	public ResponseData getSymptomsLink(@RequestParam(required = true) int id) {
		DiseaseSymptomLink link = new DiseaseSymptomLink();
		link.setDiseaseId(id);
		return new ResponseData(symptomService.queryLink(link));
	}

	@RequestMapping(value = "symptom/addSymptomsLink")
	@ResponseBody
	public ResponseData addSymptomsLink(DiseaseSymptomLink link) {

		return new ResponseData(symptomService.addSymptomsLink(link));

	}

	@RequestMapping(value = "symptom/deleteSymptomsLink")
	@ResponseBody
	public ResponseData deleteSymptomsLink(@RequestParam(required = true) Integer id) {

		return new ResponseData(symptomService.deleteSymptomsLink(id));

	}
}
